<html>

<head>
<link href="css/qam.css" rel="stylesheet" media="screen" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="css/imgareaselect-default.css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.imgareaselect.pack.js"></script>

<style>

</style>


</head>

<body>

<div class="container">

	<div class="img_box">
		<span>预览图:通过鼠标截取图片，保存你想要的部分</span><BR>
		<div class="img"><img id="photo" /></div><BR>
		<span>缩略图:系统自动生成</span><BR>
		<div class="img"><img id="thumb" /></div>
	</div>
	<div class="img_button">
		<input type="button" value="保存" onclick="adjust();" name="button">
		<input type="button" value="重新生成" onclick="re_create();" name="button">
		<input type="button" value="关闭" onclick="parent.shade_layer_close();" name="button">
	</div>

 
  <div style="float: left; width: 50%;display:none">
	x:<input type="text" id="x" value="-"><BR>
	y:<input type="text" id="y" value="-"><BR>
	w:<input type="text" id="w" value="-"><BR>
	h:<input type="text" id="h" value="-"><BR>
  </div>





</body>

<script type="text/javascript">

var parm=0;
function init(){
	parm=window.location.href.split("?")[1];
	getinfo(parm);

}

var x=y=w=h=0;
function preview(img, selection) {
    if (!selection.width || !selection.height)
        return;
	x=selection.x1;
	y=selection.y1;
	w=selection.width;
	h=selection.height;
}


/*****获取code信息********/
function getinfo(t){
	var _url=cgipath+"code-getinfo";
	var ajax_obj=new AJAX_OBJ(_url,handle_getinfo,handle_error,5000);
	ajax_obj.postData("&id="+t);
}
function handle_getinfo(xmlHttp){
	//$$("message").innerHTML=xmlHttp.responseText;return;
	eval("var ret_json="+xmlHttp.responseText);
	$$('photo').src=cgipath+ret_json.record.path_img+"?"+Math.random();
	$$('thumb').src=cgipath+ret_json.record.path_thumb+"?"+Math.random();
	$('#photo').imgAreaSelect({  handles: true,fadeSpeed: 200, onSelectChange: preview });

}


//保存图片
function adjust(){
	var _url=cgipath+"image-adjust";
	var ajax_obj=new AJAX_OBJ(_url,handle_adjust,handle_error,5000);
	if(w>0 && h>0 )ajax_obj.postData("&code_id="+parm+"&x="+x+"&y="+y+"&w="+w+"&h="+h);
}

function handle_adjust(xmlHttp){
	eval("var ret_json="+xmlHttp.responseText);
	if(ret_json.ret==0)history.go(0);

}




//重新生成图片
function re_create(){
	var _url=cgipath+"code-snapshot";
	var ajax_obj=new AJAX_OBJ(_url,handle_adjust,handle_error,5000);
	ajax_obj.postData("&code_id="+parm);
}

function handle_adjust(xmlHttp){
	//alert(xmlHttp.responseText);
	history.go(0);

}



</script>
<script src="js/ajax.js" type="text/javascript"></script>
<script src="js/public.js" type="text/javascript"></script>
<script src="js/function.js" type="text/javascript"></script>
</html>